package com.dtsz.m2.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;


import com.dtsz.m2.R;
import com.dtsz.m2.ui.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 常见问题
 */

public class CommonProblemActivity extends BaseActivity {
    private List<ImageView> ivUppers = new ArrayList<>();
    private List<TextView> tvHiddens = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_common_problem);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("常见问题");
    }

    @Override
    public void initView() {
        super.initView();
        ivUppers.add((ImageView) findViewById(R.id.iv_upper1));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper2));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper3));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper4));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper5));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper6));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper7));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper8));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper9));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper10));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper11));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper12));
        ivUppers.add((ImageView) findViewById(R.id.iv_upper13));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden2));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden3));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden4));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden5));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden6));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden7));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden8));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden9));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden10));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden11));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden12));
        tvHiddens.add((TextView) findViewById(R.id.tv_hidden13));
    }

    @Override
    public void initClick() {
        super.initClick();
        findViewById(R.id.ll_1).setOnClickListener(this);
        findViewById(R.id.ll_2).setOnClickListener(this);
        findViewById(R.id.ll_3).setOnClickListener(this);
        findViewById(R.id.ll_4).setOnClickListener(this);
        findViewById(R.id.ll_5).setOnClickListener(this);
        findViewById(R.id.ll_6).setOnClickListener(this);
        findViewById(R.id.ll_7).setOnClickListener(this);
        findViewById(R.id.ll_8).setOnClickListener(this);
        findViewById(R.id.ll_9).setOnClickListener(this);
        findViewById(R.id.ll_10).setOnClickListener(this);
        findViewById(R.id.ll_11).setOnClickListener(this);
        findViewById(R.id.ll_12).setOnClickListener(this);
        findViewById(R.id.ll_13).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.ll_1:
                selectIndex(0);
                break;
            case R.id.ll_2:
                selectIndex(1);
                break;
            case R.id.ll_3:
                selectIndex(2);
                break;
            case R.id.ll_4:
                selectIndex(3);
                break;
            case R.id.ll_5:
                selectIndex(4);
                break;
            case R.id.ll_6:
                selectIndex(5);
                break;
            case R.id.ll_7:
                selectIndex(6);
                break;
            case R.id.ll_8:
                selectIndex(7);
                break;
            case R.id.ll_9:
                selectIndex(8);
                break;
            case R.id.ll_10:
                selectIndex(9);
                break;
            case R.id.ll_11:
                selectIndex(10);
                break;
            case R.id.ll_12:
                selectIndex(11);
                break;
            case R.id.ll_13:
                selectIndex(12);
                break;
        }
    }

    private void selectIndex(int index) {
        for (int i = 0; i < tvHiddens.size(); i++) {
            if (i == index) {
                tvHiddens.get(i).setVisibility(View.VISIBLE);
                ivUppers.get(i).setBackgroundResource(R.mipmap.arrow_upper);
            } else {
                tvHiddens.get(i).setVisibility(View.GONE);
                ivUppers.get(i).setBackgroundResource(R.mipmap.arrow_lower);
            }
        }
    }
}
